/* Script for subst().js created Mon Apr 04 13:09:00 SGT 2005 */

function subst(str, ch1, ch2)
{
	var idx = str.indexOf(ch1);
	if (idx<0) return str;
	
	var ret = str;
	var len = str.length;
	while (idx>=0)
	{
		ret = ret.substring(0,idx) + ch2 + ret.substring(idx+1,len);
		idx = ret.indexOf(ch1,idx);
	}
	return ret;
}

//Java script replace only replaces the first instance. This function replaces all instances without going into a endless loop replacing the same 'toberep' and 'repwith'.

function xreplace(checkMe,toberep,repwith)
{
   var temp = checkMe;
   var i = temp.indexOf(toberep);
   while(i > -1)
   {
      temp = temp.replace(toberep, repwith);
      i = temp.indexOf(toberep, i + repwith.length + 1);
   }
   return temp;
}

/*
If you use a regular expression with Javascript Replace it will replace all instances. For example.

var t = /-/g;
var b = "-----TTTT";
b.replace(t, "t");

This will result in all the "-" being replaced with "t".

*/
